﻿using System;

namespace InputDocument.Models
{
    class Student
    {
        public string Name { get; set; }
        public string StudentNumber { get; set; }
        public string PhoneNumber { get; set; }
        public int Score { get; set; }
        public DateTime Birthday { get; set; }

        /// <summary>
        /// 只读属性 年龄
        /// </summary>
        public int Age
        {
            get
            {
                return DateTime.Today.Year - Birthday.Year + 1;
            }
        }

        ///<summary>
        ///构造函数
        ///</summary>
        public Student(string name, string studentnumber, string phonenumber, int score, DateTime birthday)
        {
            Name = name;
            StudentNumber = studentnumber;
            PhoneNumber = phonenumber;
            Score = score;
            Birthday = birthday;
        }

        /// <summary>
        /// 从数据文件的一行转换一个student对象
        /// </summary>
        public Student(string line)
        {
            string[] sArray = line.Split(' ', (char)StringSplitOptions.RemoveEmptyEntries);
            Name = sArray[0];
            StudentNumber = sArray[1];
            PhoneNumber = sArray[2];
            Birthday = Convert.ToDateTime(sArray[4]);
            Score = Convert.ToInt32(sArray[3]);
        }
    }
}
